<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Code Highlight with Line Numbers</title>
    <!-- 引入 Highlight.js 样式 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/styles/atom-one-dark.min.css">
    <!-- 引入行号插件的样式 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/styles.css">
    <!-- 引入编程字体 -->
    <link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Fira Code', monospace;
            background-color: #282c34;
            color: #abb2bf;
            padding: 20px;
        }
        pre {
            overflow: auto;
            border-radius: 5px;
        }
        code {
            display: block;
            padding: 10px;
            background-color: #282c34;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <pre><code class="cpp">
    // 在这里粘贴你的C++代码
    #include "session_manager.h"
    #include "nlohmann/json.hpp"
    #include "../common/common.h"
    
    namespace ArrowWebSocket
    {
    
    CSessionManager::CSessionManager()
    {
    }
    
    CSessionManager::~CSessionManager()
    {
        Deini();
    }
    
    void CSessionManager::Init(asio::io_context& ioContext)
    {
        m_pTimer = new asio::steady_timer(ioContext);
    }
    
    void CSessionManager::Run()
    {
        DoReadQueue();
        return;
    }
    
    void CSessionManager::Deini()
    {
        if(m_pTimer != nullptr)
        {
            m_pTimer->cancel();
            delete m_pTimer;
            m_pTimer = nullptr;
        }
    }
    
    void CSessionManager::AddSession(SharedPtrISession pSession)
    {
        if(m_setSessions.find(pSession) != m_setSessions.end())
            return;
    
        if(m_setMsgSrcInfo.size() > 0 )
        {
            std::string strTmpAllMsgSrcInfo;
            nlohmann::json j;
            for (auto& it : m_setMsgSrcInfo)
            {
                j.push_back(it);
            }
            strTmpAllMsgSrcInfo = j.dump();
            pSession->PutAllMsgSrcInfo(strTmpAllMsgSrcInfo);
        }
    
        m_setSessions.insert(pSession);
    }
    
    void CSessionManager::RemoveSession(SharedPtrISession pSession)
    {
        m_setSessions.erase(pSession);
        if(m_setSessions.size() == 0)
        {
            m_setMsgSrcInfo.clear();
        }
    }
    
    void CSessionManager::PutMsg(const SharedPtrMsg& pMsg)
    {
        m_msgQueue.Push(pMsg);
    }
    
    void CSessionManager::DoReadQueue()
    {
        // if (m_msgQueue.Empty())
        // {
        //     // 启动定时器 10毫秒后再次调用
        //     m_pTimer->expires_after(std::chrono::milliseconds(10));
        //     m_pTimer->async_wait([this](beast::error_code ec) {
        //         if (!ec)
        //         {
        //             DoReadQueue();
        //         }
        //     });
        //     return;
        // }
        // SharedPtrMsg pMsg;
        // if( false == m_msgQueue.Pop(pMsg))
        // {
        //     return;
        // }
    
        // auto it = m_setMsgSrcInfo.find(pMsg->SrcInfo());
        // if(it == m_setMsgSrcInfo.end())
        // {
        //     m_setMsgSrcInfo.insert(pMsg->SrcInfo());
        //     nlohmann::json j;
        //     j["msg_type"] = static_cast<int32_t>(EmMsgType::AllMsgSrcInfo);
        //     for (auto& it : m_setMsgSrcInfo)
        //     {
        //         j["msg_src_info"].push_back(it);
        //     }
        //     std::string strtmp = j.dump();
    
        //     for (auto& it : m_setSessions)
        //     {
        //         it->PutAllMsgSrcInfo(strtmp);11111111111111111111111111111111111111111111111111111111111111
        //     }
        // }
    
        // for (auto& it : m_setSessions)
        // {
        //     it->PutMsg(pMsg);
        // }    
        // DoReadQueue();
    }
    
    int32_t CSessionManager::Count()
    {
        return m_setSessions.size();
    }
    
    } // namespace ArrowWebSocket
    
</code></pre>
<!-- 引入 Highlight.js 核心库 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/highlight.min.js"></script>
<!-- 引入行号插件的 JS -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script> -->
<script src="../highlight/highlightjs-line-numbers.min.js"></script>
<script>
    // 初始化代码高亮
    hljs.highlightAll();
    // 初始化行号插件
    hljs.initLineNumbersOnLoad();
</script>
</body>
</html>